package com.zzzy.controller;


import com.zzzy.config.DataSource;
import com.zzzy.config.DataSourceContextHolder;
import com.zzzy.po.User;
import com.zzzy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping( value = "/user/{id}")
    public User getUser(@PathVariable("id") int id, HttpServletRequest request){
        User user = userService.findUser( id);

        return user;
    }

//    @ResponseBody
//    @RequestMapping( value = "/usr/{id}")
//    public User getUsr(@PathVariable("id") int id, HttpServletRequest request){
//        User user = userService.findUser( id);
//
//        return user;
//    }

    @ResponseBody
    @RequestMapping( value = "/login/{tenent}")
    public String getT(@PathVariable("tenent") String tenent, HttpServletRequest request){

        request.getSession().setAttribute("tenent", tenent);
        return "租户‘" +tenent+"’登录成功";
    }
}
